package com.yun.datastructure.linear.queue;

import java.util.LinkedList;

public class MonotonicQueue {

    private LinkedList<Integer> deque=new LinkedList<>();

    public Integer peek(){
        return deque.peekFirst();
    }

    public void poll(){
        deque.pollFirst();
    }

    public void offer(Integer t){
        while (!deque.isEmpty() && deque.peekLast()<t){
            deque.pollLast();
        }
        deque.offerLast(t);
    }

    @Override
    public String toString() {
        return deque.toString();
    }

    public static void main(String[] args) {
        MonotonicQueue q=new MonotonicQueue();
        int[] nums={1,3,-1,-3,5,3,6,7};
        for (int i : nums) {
            q.offer(i);
            System.out.println(q);
        }
    }
}
